import Vue from 'vue';
import App from './App.vue';
import router from './router';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import '../src/utils/request';  //引入axios配置
import axios from 'axios';
import Vuex from 'vuex';
import Chat from 'jwchat';
import global_msg from './common/js/Global';  //引入全局变量
/* 在 0.2.041 之前的版本需要引入 css */
// import 'jwchat/lib/JwChat.css';
Vue.use(Chat);
Vue.prototype.$global_msg = global_msg;
Vue.prototype.axios=axios;

Vue.config.productionTip = false
Vue.use(ElementUI, { size: 'small' });
Vue.use(ElementUI);
Vue.use(Vuex);

//路由跳转之前
router.beforeEach((to,from,next)=>{
  let Authorization=sessionStorage.getItem('tokenValue');

  if (to.path=='/logout'){
    //清空
    sessionStorage.clear();
    //跳转到登录页面
    next({path:'/login'});
  } else if (to.path=='/login'){
    //判断是否为空
    if (Authorization!=null){
      next({path:'/main'})
    }
  } else if (Authorization==null){
    next({path:'/login'})
  }
  next();
});

new Vue({
  router,
  render: h => h(App),
}).$mount('#app')
